package com.luxury.adpter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.google.gson.Gson;
import com.luxury.HomeType1Activity;
import com.luxury.HomeWebActivity;
import com.luxury.ProductActivity;
import com.luxury.R;
import com.luxury.bean.BannerContentBean;
import com.luxury.bean.ChildType12Bean;
import com.luxury.bean.HomeBean;
import com.luxury.bean.Type10Bean;
import com.luxury.bean.Type12Bean;
import com.luxury.bean.Type12BeanEnd;
import com.luxury.bean.Type1Bean;
import com.luxury.bean.Type1BeanEnd;
import com.luxury.bean.Type4or5Bean;
import com.luxury.bean.Type6Bean;
import com.luxury.bean.Type7Bean;
import com.luxury.bean.Type8Bean;
import com.luxury.bean.Type9Bean;
import com.luxury.decoration.DividerGridItemDecoration;
import com.luxury.decoration.SpacesItemDecoration;
import com.luxury.helper.RecyclerViewAdapterHelper;
import com.luxury.r_innerface.InterfaceLuxury;
import com.luxury.utils.GlideImageLoader;
import com.luxury.utils.URLContants;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerClickListener;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

import static android.content.ContentValues.TAG;

/**
 * Created by Administrator on 2016/12/13.
 */

public class HomeRecyclerAdapter extends RecyclerViewAdapterHelper<HomeBean.FloorsBean> {
    private Gson mGson = new Gson();
    private String mJson = "";
    private List<String> mList_type4or5Img = new ArrayList<>();
    private View mView = null;
    private String mUrl = "";
    private String mMUrl = "http://m.secoo.com/";
    private String mLasUrl = "http://las.secoo.com/api/";
    private String mAndroidUrl = "http://android.secoo.com/appActivity/";
    private Handler handler;

    public HomeRecyclerAdapter(Context mContext, List<HomeBean.FloorsBean> list) {
        super(mContext, list);
    }

    //item多布局
    @Override
    public int getItemViewType(int position) {
        return mList.get(position).getType();
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {

        switch (viewType) {
            case 1:
                mView = mInflater.inflate(R.layout.item_type1_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType1(mView);
            case 2:
                mView = mInflater.inflate(R.layout.item_banner_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderBanner(mView);
            case 3:
                mView = mInflater.inflate(R.layout.item_type3_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType3(mView);
            case 4:
                mView = mInflater.inflate(R.layout.item_type4_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType4(mView);
            case 5:
                mView = mInflater.inflate(R.layout.item_type5_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType5(mView);
            case 6:
                mView = mInflater.inflate(R.layout.item_type6_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType6(mView);
            case 7:
                mView = mInflater.inflate(R.layout.item_type7_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType7(mView);
            case 9:
                mView = mInflater.inflate(R.layout.item_type9_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType9(mView);
            case 8:
                mView = mInflater.inflate(R.layout.item_type8_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType8(mView);
            case 10:
                mView = mInflater.inflate(R.layout.item_type9_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType10(mView);
            case 12:
                mView = mInflater.inflate(R.layout.item_type12_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderType12(mView);
            default:
                mView = mInflater.inflate(R.layout.item_text_homefragment, parent, false);
                return new HomeRecyclerAdapter.ViewHolderTest(mView);
        }

    }

    //--------------------------recyclerView item点击事件 当type=4,5,7,
    // 8时候的封装方法---------------------------------
    public void checkItemTo(String activityId, int position) {
        Log.i(TAG, "activityId---->>>:" + activityId);
        if (activityId.contains("/")) {
            String[] split = activityId.split("/");
            mUrl = mLasUrl + split[0] + "/" + split[0] + "_list?id=" + split[1] +
                    "&share=nativeShare&pageid=" + activityId;
            Log.i(TAG, "大牌男鞋的网址" + mUrl);
        } else {
            mUrl = mAndroidUrl + activityId + ".shtml?share=nativeShare&pageid=" + activityId;
            Log.i(TAG, "其余除了新客专享" + mUrl);
        }
        Intent intent = new Intent(mContext, HomeWebActivity.class);
        intent.putExtra("url", mUrl);
        intent.putExtra("tabIndex", position);
        mContext.startActivity(intent);
    }

    @Override
    public void onBindMyViewHolder(final RecyclerView.ViewHolder holder, int position) {
        final int fPosition = position;
        mJson = mList.get(position).getContent();
        mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG, "点击的位置: " + fPosition);
                switch (mList.get(fPosition).getType()) {
                    case 4:
                        checkItemTo(mGson.fromJson(mList.get(fPosition).getContent(),
                                Type4or5Bean.class).getActivityId(), fPosition);
                        break;
                    case 5:
                        checkItemTo(mGson.fromJson(mList.get(fPosition).getContent(),
                                Type4or5Bean.class).getActivityId(), fPosition);
                        break;
                    case 7:
                        checkItemTo(mGson.fromJson(mList.get(fPosition).getContent(), Type7Bean
                                .class).getActivityId(), fPosition);
                        break;
                    case 8:
                        checkItemTo(mGson.fromJson(mList.get(fPosition).getContent(), Type8Bean
                                .class).getActivityId(), fPosition);
                        break;
                }
            }
        });

        //      如果是banner类型的
        if (holder instanceof HomeRecyclerAdapter.ViewHolderBanner) {
            //            设置banner
            initBanner(holder, position, mJson);
        }
        //type1是导航栏
        else if (holder instanceof HomeRecyclerAdapter.ViewHolderType1) {
            initType1(holder, position, mJson);

        } else if (holder instanceof HomeRecyclerAdapter.ViewHolderType4) {
            initType4Or5(holder, position, mJson);

            Glide.with(mContext).load(mList_type4or5Img.get(0))
                    //添加动画效果
                    .into(((ViewHolderType4) holder).ivleft_itemtype4);

            Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.scale_type4or5);
            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    Log.i("======","======onAnimationStart");
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    Log.i("======","======onAnimationEnd");
                    ((ViewHolderType4) holder).ivleft_itemtype4.setAnimation(animation);
                    animation.start();
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    Log.i("======","======onAnimationRepeat");
                }
            });

            ((ViewHolderType4) holder).ivleft_itemtype4.setAnimation(animation);



            Glide.with(mContext).load(mList_type4or5Img.get(1)).into(((ViewHolderType4) holder)
                    .ivright_item_type4);
        } else if (holder instanceof HomeRecyclerAdapter.ViewHolderType5) {
            initType4Or5(holder, position, mJson);
            Glide.with(mContext).load(mList_type4or5Img.get(0)).into(((ViewHolderType5) holder)
                    .ivleft_itemtype5);
            Glide.with(mContext).load(mList_type4or5Img.get(1)).animate(R.anim.scale_type4or5)
                    //添加动画效果
                    .into(((ViewHolderType5) holder).ivright_item_type5);
        } else if (holder instanceof HomeRecyclerAdapter.ViewHolderType6) {
            initType6(holder, position, mJson);//没写完
        } else if (holder instanceof HomeRecyclerAdapter.ViewHolderType7) {
            initType7(holder, position, mJson);
        } else if (holder instanceof HomeRecyclerAdapter.ViewHolderType8) {
            initType8(holder, position, mJson);
        } else if (holder instanceof HomeRecyclerAdapter.ViewHolderType9) {
            initType9(holder, position, mJson);
        } else if (holder instanceof HomeRecyclerAdapter.ViewHolderType10) {
            initType10(holder, position, mJson);
        } else if (holder instanceof HomeRecyclerAdapter.ViewHolderType12) {
//            initType12End(holder, position, mJson);
            initType12(holder, position, mJson);
            Log.i(TAG, "type12--->>: " + mJson);
        } else if (holder instanceof ViewHolderTest) {
            ((ViewHolderTest) holder).tv_item_test.setText("类型:" + mList.get(position).getType());
        }

    }


    private void initType12(final RecyclerView.ViewHolder holder, int position, String mJson) {
        final Type12Bean type12Bean = mGson.fromJson(mJson, Type12Bean.class);
        String hotName = type12Bean.getHotName();
        String hotUrl = type12Bean.getHotUrl();
        final String femaleName = type12Bean.getFemaleName();
        String femaleUrl = type12Bean.getFemaleUrl();
        String maleName = type12Bean.getMaleName();
        String maleUrl = type12Bean.getMaleUrl();
        final List<ChildType12Bean.ProductListBean>[] product_list = new List[1];
        final Type12RecyclerAdapter[] adapter = {new Type12RecyclerAdapter(mContext,
                product_list[0])};
        final String[] productType = {"1"};
        ((ViewHolderType12) holder).rBtn_itemType12_typename1.setText(hotName);
        ((ViewHolderType12) holder).rBtn_itemType12_typename1.setChecked(true);
        ((ViewHolderType12) holder).rBtn_itemType12_typename2.setText(maleName);
        ((ViewHolderType12) holder).rBtn_itemType12_typename3.setText(femaleName);

        //设置type=12 的recyclerView
        GridLayoutManager manager = new GridLayoutManager(mContext, 2);
        ((ViewHolderType12) holder).rv_itemType12.setLayoutManager(manager);
        ((ViewHolderType12) holder).rv_itemType12.addItemDecoration(new SpacesItemDecoration(5));
//        解析hot的网址
        Retrofit retrofit = new Retrofit.Builder().baseUrl(URLContants.BASE_TYPE12URL)
                .addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory
                        (RxJavaCallAdapterFactory.create()).build();
        final InterfaceLuxury interfaceLuxury = retrofit.create(InterfaceLuxury.class);
        Observable<ChildType12Bean> type12Bean_ob = interfaceLuxury.getChildType12Bean
                (productType[0]);
        Log.i(TAG, "initType12: -----" + productType[0]);
        type12Bean_ob.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<ChildType12Bean>() {
            @Override
            public void call(ChildType12Bean childtype12Bean) {
                product_list[0] = childtype12Bean.getProductList();
                adapter[0] = new Type12RecyclerAdapter(mContext, product_list[0]);
                ((ViewHolderType12) holder).rv_itemType12.setAdapter(adapter[0]);
                Log.i(TAG, "传的集合是???" + product_list[0].toString());
            }
        });
        //给radioGroup添加点击事件
        ((ViewHolderType12) holder).rg_itemType12.setOnCheckedChangeListener(new RadioGroup
                .OnCheckedChangeListener() {
            Retrofit retrofit = new Retrofit.Builder().baseUrl(URLContants.BASE_TYPE12URL)
                    .addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory
                            (RxJavaCallAdapterFactory.create()).build();
            final InterfaceLuxury interfaceLuxury = retrofit.create(InterfaceLuxury.class);

            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
                switch (checkId) {
                    case R.id.rBtn_itemType12_typename1:
                        productType[0] = "1";
                        break;
                    case R.id.rBtn_itemType12_typename2:
                        productType[0] = "2";
                        break;
                    case R.id.rBtn_itemType12_typename3:
                        productType[0] = "3";
                        break;
                }
                Observable<ChildType12Bean> type12Bean_ob = interfaceLuxury.getChildType12Bean
                        (productType[0]);
                Log.i(TAG, "initType12: -----" + productType[0]);
                type12Bean_ob.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread
                        ()).subscribe(new Action1<ChildType12Bean>() {
                    @Override
                    public void call(ChildType12Bean childtype12Bean) {
                        List<ChildType12Bean.ProductListBean> product_list = childtype12Bean
                                .getProductList();
                        adapter[0].reloadRecyclerView(product_list, true);

                    }
                });
            }

        });
    }

    private void initType8(RecyclerView.ViewHolder holder, int position, String mJson) {
        String img = mGson.fromJson(mJson, Type8Bean.class).getImg();
        Glide.with(mContext).load(img).into(((ViewHolderType8) holder).iv_itemtype8);

    }

    private void initType9(RecyclerView.ViewHolder holder, int position, String mJson) {
        List<Type9Bean.BrandBean> list_brand = mGson.fromJson(mJson, Type9Bean.class).getBrand();
        ImageView[] imgArr = new ImageView[list_brand.size()];
        for (int i = 0; i < list_brand.size(); i++) {
            //    动态加载imageView
            imgArr[i] = new ImageView(mContext);
            ((ViewHolderType9) holder).layout_itemType9.addView(imgArr[i]);
            Glide.with(mContext).load(list_brand.get(i).getImg()).into(imgArr[i]);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(150, 150);
            //            lp.width=150;
            //            lp.height=150;
            lp.gravity = Gravity.CENTER;
            lp.setMargins(5, 0, 5, 0);
            imgArr[i].setLayoutParams(lp);
            //            设置每个的点击事件(还没设置呢)


        }
    }

    private void initType10(RecyclerView.ViewHolder holder, int position, String s) {
        mJson = mList.get(position).getContent();
//        Log.i(TAG, "Type1的content-->>" + mJson);
        List<Type10Bean.ProductBean> list_product = mGson.fromJson(mJson, Type10Bean.class)
                .getProduct();
        //创建textView数组
        final LinearLayout[] layoutArr = new LinearLayout[list_product.size()];
        String brand, img, price = "";
        ((ViewHolderType10) holder).layout_itemType10.removeAllViews();
        for (int i = 0; i < list_product.size(); i++) {
            String id = list_product.get(i).getId();
//            取每一个的品牌
            brand = list_product.get(i).getBrandNameEN();
//            取每一个的图片网址
            img = "http://pic11.secooimg.com/product/300/300/" + list_product.get(i).getPicUrl();
//            每一个的价格
            price = list_product.get(i).getSecooPrice();
//            取每一个点击跳转的页面
//            url = list_product.get(i).getUrl();
//            添加 属相布局
            layoutArr[i] = new LinearLayout(mContext);
            layoutArr[i].setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams
                    .WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
            lp.setMargins(40, 10, 40, 15);
            lp.gravity = Gravity.CENTER;
            layoutArr[i].setLayoutParams(lp);
            ImageView iv = new ImageView(mContext);
            Glide.with(mContext).load(img).into(iv);
            LinearLayout.LayoutParams layout_lp = new LinearLayout.LayoutParams(200, 200);
            layout_lp.gravity = Gravity.CENTER;
            iv.setLayoutParams(layout_lp);
            TextView tv_brandName = new TextView(mContext);
            tv_brandName.setText(brand);
            tv_brandName.setGravity(Gravity.CENTER);
            TextView tv_price = new TextView(mContext);
            tv_price.setText("￥" + price);
            tv_price.setTextSize(10);
            tv_price.setGravity(Gravity.CENTER);
            ((ViewHolderType10) holder).layout_itemType10.addView(layoutArr[i]);
            layoutArr[i].addView(iv);
            layoutArr[i].addView(tv_brandName);
            layoutArr[i].addView(tv_price);
            final String finalImg = img;
            final String finalId=id;
            layoutArr[i].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent=new Intent(mContext, ProductActivity.class);
                    intent.putExtra("imgHead", finalImg);
                    intent.putExtra("productId",finalId);
                    mContext.startActivity(intent);
                }
            });
        }
    }

    private void initType7(RecyclerView.ViewHolder holder, int position, String mJson) {
        Type7Bean type7Bean = mGson.fromJson(mJson, Type7Bean.class);
        String img = type7Bean.getImg();
        String title = type7Bean.getTitle();
        String subTitle = type7Bean.getSubTitle();
        Glide.with(mContext).load(img).into(((ViewHolderType7) holder).iv7_itemType7);
        ((ViewHolderType7) holder).tv_title_itemType7.setText(title);
        ((ViewHolderType7) holder).tv_subtitle_itemType7.setText(subTitle);

    }
    List<Type6Bean.RushRobListBean> list_rushrob;

    private void initType6(final RecyclerView.ViewHolder holder, final int position, final String s) {
//
//        if(list_rushrob!=null){
//            //显示数据
//        }else {
//            //下载
//            //显示
//        }

        //        解析json  用retrofit和RXjava做
        Retrofit retrofit = new Retrofit.Builder().baseUrl(URLContants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory
                        (RxJavaCallAdapterFactory.create()).build();
        InterfaceLuxury interfaceLuxury = retrofit.create(InterfaceLuxury.class);
        Observable type6Bean_ob = interfaceLuxury.getType6Bean();
        type6Bean_ob.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<Type6Bean>() {
            @Override
            public void call(Type6Bean type6Bean) {
//--------------------------------倒计时-------------------------------
                long endTime = type6Bean.getEndTime();
                countDown(holder, endTime);

//-----------------------加载横向滚动--------------------------------------------------
                list_rushrob = type6Bean.getRush_rob_list();
                String brandName, img, secooPrice, pId = "";
                //创建布局数组
                LinearLayout[] layoutwArr = new LinearLayout[list_rushrob.size()];
                ((ViewHolderType6) holder).layout_itemType6.removeAllViews();
                final String url = "http://android.secoo.com/appActivity/sqh_list.shtml?share=nativeShare&title=%E5%A5%A2%E6%8A%A2%E6%83%A0&pid=";
                for (int i = 0; i < list_rushrob.size(); i++) {
                    // 选取需要得到的数据
                    brandName = list_rushrob.get(i).getBrandCnName() + "  " + list_rushrob.get(i)
                            .getBrandEnName();
                    img = list_rushrob.get(i).getImageUrl();
                    secooPrice = "￥" + list_rushrob.get(i).getSecooPrice();
                    pId=list_rushrob.get(i).getProductId();
                    int size = list_rushrob.get(i).getSize();

                    //动态生成现行布局
                    layoutwArr[i] = new LinearLayout(mContext);
                    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(600, ViewGroup
                            .LayoutParams.MATCH_PARENT);
                    lp.gravity = Gravity.CENTER;
                    lp.setMargins(20, 0, 20, 20);
                    layoutwArr[i].setBackgroundColor(Color.argb(8, 0, 0, 0));
                    layoutwArr[i].setOrientation(LinearLayout.HORIZONTAL);
                    layoutwArr[i].setLayoutParams(lp);
                    ((ViewHolderType6) holder).layout_itemType6.addView(layoutwArr[i]);
                    ImageView iv = new ImageView(mContext);
                    LinearLayout.LayoutParams iv_lp = new LinearLayout.LayoutParams(250,
                            ViewGroup.LayoutParams.MATCH_PARENT);
                    iv_lp.gravity = Gravity.CENTER;
                    //给图片设置margin
                    iv_lp.setMargins(20, 10, 20, 20);
//                    iv.setBackgroundColor(Color.rgb( 0, 0, 0));
                    iv.setLayoutParams(iv_lp);
                    Glide.with(mContext).load(img).into(iv);
                    layoutwArr[i].addView(iv);
//                  创建装连个textView的垂直布局
                    LinearLayout linearLayout = new LinearLayout(mContext);
                    linearLayout.setOrientation(LinearLayout.VERTICAL);
                    linearLayout.setGravity(Gravity.CENTER);
                    LinearLayout.LayoutParams layout_lp = new LinearLayout.LayoutParams(ViewGroup
                            .LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                    layout_lp.gravity = Gravity.CENTER;
                    linearLayout.setLayoutParams(layout_lp);
                    layoutwArr[i].addView(linearLayout);
                    TextView tv_band = new TextView(mContext);
                    TextView tv_price = new TextView(mContext);
                    tv_band.setText(brandName);
                    tv_price.setText(secooPrice);
                    tv_band.setGravity(Gravity.CENTER_VERTICAL);
                    tv_band.setTextSize(15);
                    tv_price.setGravity(Gravity.CENTER_VERTICAL);
                    tv_price.setTextSize(20);
                    linearLayout.addView(tv_band);
                    linearLayout.addView(tv_price);
                    if (size < 10) {
                        TextView tv_size = new TextView(mContext);
                        tv_size.setText("仅剩 " + size + " 件");
                        tv_size.setTextSize(10);
                        tv_size.setTextColor(Color.RED);
                        linearLayout.addView(tv_size);
                    }

                    final int finalI = i;
                    final String finalPId = pId;
                    layoutwArr[i].setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {

                            Intent intent = new Intent(mContext, HomeType1Activity.class);
                            //传值
                            intent.putExtra("url", url+ finalPId);
                            intent.putExtra("type", mList.get(position).getType());
                            intent.putExtra("tabIndex", finalI);
                            mContext.startActivity(intent);
                        }
                    });
                }
            }
                });

    }

    private void initType4Or5(RecyclerView.ViewHolder holder, int position, String s) {
        Log.i(TAG, "initType4: " + s);
        Type4or5Bean type4or5Bean = mGson.fromJson(s, Type4or5Bean.class);
        mList_type4or5Img = type4or5Bean.getImg();

    }

    private void initType1(RecyclerView.ViewHolder holder, final int position, String s) {
        mJson = mList.get(position).getContent();
        Log.i(TAG, "Type1的content-->>" + mJson);
        List<Type1Bean.AccessBean> list_access = mGson.fromJson(mJson, Type1Bean.class).getAccess();

        //创建textView数组
        final TextView[] textViewArr = new TextView[list_access.size()];
        String title, img, url = "";
        ((HomeRecyclerAdapter.ViewHolderType1) holder).layout_item_type1.removeAllViews();
        for (int i = 0; i < list_access.size(); i++) {
            //            取每一个的title
            title = list_access.get(i).getTitle();
            //            取每一个的图片网址
            img = list_access.get(i).getImg();
            //            取每一个点击跳转的页面
            url = list_access.get(i).getUrl();
            //            动态创建textView
            textViewArr[i] = new TextView(mContext);
            final int finalI = i;
            Glide.with(mContext).load(img).asBitmap().into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap>
                        glideAnimation) {
                    //                    将bitmap对象转成drawable对象
                    BitmapDrawable bd = new BitmapDrawable(mContext.getResources(), resource);
                    bd.setBounds(0, 0, bd.getMinimumWidth(), bd.getMinimumHeight());
                    //                    将当前的textview上边设置图片
                    textViewArr[finalI].setCompoundDrawables(null, bd, null, null);
                }
            });
            //设置textview的属性
            textViewArr[i].setText(title);//设置text的文字
            textViewArr[i].setTextColor(mContext.getResources().getColor(R.color.gray));//设置文字颜色
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup
                    .LayoutParams.MATCH_PARENT);
            lp.weight = 1;
            lp.setMargins(0, 10, 0, 0);
            lp.gravity = Gravity.CENTER;
            textViewArr[i].setLayoutParams(lp);//权重'
            textViewArr[i].setGravity(Gravity.CENTER);
            //            在布局中动态添加textView
            ((HomeRecyclerAdapter.ViewHolderType1) holder).layout_item_type1.addView
                    (textViewArr[i]);
            //            给textView设置点击事件
            final String finalUrl = url;
            textViewArr[i].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mContext, HomeType1Activity.class);
                    //传值
                    intent.putExtra("url", finalUrl);
                    intent.putExtra("tabIndex", finalI);
                    intent.putExtra("type", mList.get(position).getType());
                    mContext.startActivity(intent);
                }
            });
        }
    }

    //-------------------------banner的holder---------------------------------------------
    class ViewHolderBanner extends RecyclerView.ViewHolder {
        private Banner banner_ItemHomefragment;

        public ViewHolderBanner(View itemView) {
            super(itemView);
            banner_ItemHomefragment = (Banner) itemView.findViewById(R.id.banner_item_homefragment);
        }
    }

    //--------------------------Type1的holder---------------------------------------------
    class ViewHolderType1 extends RecyclerView.ViewHolder {
        private LinearLayout layout_item_type1;

        public ViewHolderType1(View itemView) {
            super(itemView);
            layout_item_type1 = (LinearLayout) itemView.findViewById(R.id.layout_item_type1);
        }
    }

    //    //--------------------------Type3的holder---------------------------------------------
    class ViewHolderType3 extends RecyclerView.ViewHolder {
        private View view_item_type3;

        public ViewHolderType3(View itemView) {
            super(itemView);
            view_item_type3 = itemView.findViewById(R.id.view_item_type3);
        }
    }

    //--------------------------Type4的holder---------------------------------------------
    class ViewHolderType4 extends RecyclerView.ViewHolder {
        private ImageView ivleft_itemtype4, ivright_item_type4;

        public ViewHolderType4(View itemView) {
            super(itemView);
            ivleft_itemtype4 = (ImageView) itemView.findViewById(R.id
                    .ivleft_item_type4_homefragment);
            ivright_item_type4 = (ImageView) itemView.findViewById(R.id
                    .ivright_item_type4_homefragment);
        }
    }

    //--------------------------Type5的holder---------------------------------------------
    class ViewHolderType5 extends RecyclerView.ViewHolder {
        private ImageView ivleft_itemtype5, ivright_item_type5;

        public ViewHolderType5(View itemView) {
            super(itemView);
            ivleft_itemtype5 = (ImageView) itemView.findViewById(R.id
                    .ivleft_item_type5_homefragment);
            ivright_item_type5 = (ImageView) itemView.findViewById(R.id
                    .ivright_item_type5_homefragment);
        }
    }

    //--------------------------Type6的holder---------------------------------------------
    class ViewHolderType6 extends RecyclerView.ViewHolder {
        private TextView tv_house_itemType6, tv_minute_itemType6, tv_second_itemType6;
        private LinearLayout layout_itemType6;

        public ViewHolderType6(View itemView) {
            super(itemView);
            tv_house_itemType6 = (TextView) itemView.findViewById(R.id.tv_house_itemType6);
            tv_minute_itemType6 = (TextView) itemView.findViewById(R.id.tv_minute_itemType6);
            tv_second_itemType6 = (TextView) itemView.findViewById(R.id.tv_second_itemType6);
            layout_itemType6 = (LinearLayout) itemView.findViewById(R.id.layout_item_type6);
        }
    }

    //--------------------------Type7的holder---------------------------------------------
    class ViewHolderType7 extends RecyclerView.ViewHolder {
        private ImageView iv7_itemType7;
        private TextView tv_title_itemType7, tv_subtitle_itemType7;

        public ViewHolderType7(View itemView) {
            super(itemView);
            iv7_itemType7 = (ImageView) itemView.findViewById(R.id.iv7_itemType7_homefragment);
            tv_title_itemType7 = (TextView) itemView.findViewById(R.id
                    .tv_title_itemType7_homefragment);
            tv_subtitle_itemType7 = (TextView) itemView.findViewById(R.id
                    .tv_subtitle_itemType7_homefragment);

        }
    }

    //--------------------------Type8的holder---------------------------------------------
    class ViewHolderType8 extends RecyclerView.ViewHolder {
        private ImageView iv_itemtype8;

        public ViewHolderType8(View itemView) {
            super(itemView);
            iv_itemtype8 = (ImageView) itemView.findViewById(R.id.iv_itemType8_homefragment);

        }
    }

    //--------------------------Type9的holder---------------------------------------------
    class ViewHolderType9 extends RecyclerView.ViewHolder {
        private LinearLayout layout_itemType9;

        public ViewHolderType9(View itemView) {
            super(itemView);
            layout_itemType9 = (LinearLayout) itemView.findViewById(R.id.layout_itemType9);

        }
    }

    //--------------------------Type10的holder---------------------------------------------
    class ViewHolderType10 extends RecyclerView.ViewHolder {
        private LinearLayout layout_itemType10;

        public ViewHolderType10(View itemView) {
            super(itemView);
            layout_itemType10 = (LinearLayout) itemView.findViewById(R.id.layout_itemType9);

        }
    }

    //--------------------------Type12的holder---------------------------------------------
    class ViewHolderType12 extends RecyclerView.ViewHolder {
        private RadioButton rBtn_itemType12_typename1, rBtn_itemType12_typename2,
                rBtn_itemType12_typename3;
        private RecyclerView rv_itemType12;
        private RadioGroup rg_itemType12;

        public ViewHolderType12(View itemView) {
            super(itemView);
            rv_itemType12 = (RecyclerView) itemView.findViewById(R.id.rv_itemType12);
            rg_itemType12 = (RadioGroup) itemView.findViewById(R.id.rg_itemType12);
            rBtn_itemType12_typename1 = (RadioButton) itemView.findViewById(R.id
                    .rBtn_itemType12_typename1);
            rBtn_itemType12_typename2 = (RadioButton) itemView.findViewById(R.id
                    .rBtn_itemType12_typename2);
            rBtn_itemType12_typename3 = (RadioButton) itemView.findViewById(R.id
                    .rBtn_itemType12_typename3);
        }
    }

    //--------------------------Test的holder---------------------------------------------
    class ViewHolderTest extends RecyclerView.ViewHolder {
        private TextView tv_item_test;

        public ViewHolderTest(View itemView) {
            super(itemView);
            tv_item_test = (TextView) itemView.findViewById(R.id.tv_item_test);
        }
    }

    //---------------------------封装设置banner的方法------------------------------------------
    private void initBanner(RecyclerView.ViewHolder holder, int position, String s) {
        Log.i(TAG, "轮播图的content-->>" + mList.get(position).getContent());
        //            用来存储图片的list
        List<String> list_bannerImg = new ArrayList<>();
        List<String> list_bannerTiele = new ArrayList<>();
        //            得到图片数据

        mJson = mList.get(position).getContent();
        //            gosn解析
        List<BannerContentBean.BannerBean> list_banner = mGson.fromJson(mJson, BannerContentBean
                .class).getBanner();
        for (int i = 0; i < list_banner.size(); i++) {
            //                String img = list_banner.get(i).getImg();
            //                将图片放到图片集合中
            list_bannerImg.add(list_banner.get(i).getImg());
            list_bannerTiele.add(list_banner.get(i).getTitle() + "");
        }
        //给banner设置样式
        ((HomeRecyclerAdapter.ViewHolderBanner) holder).banner_ItemHomefragment.setBannerStyle
                (BannerConfig.CIRCLE_INDICATOR_TITLE);
        //设置图片加载器
        ((HomeRecyclerAdapter.ViewHolderBanner) holder).banner_ItemHomefragment.setImageLoader
                (new GlideImageLoader());
        //设置图片集合
        ((HomeRecyclerAdapter.ViewHolderBanner) holder).banner_ItemHomefragment.setImages
                (list_bannerImg);
        //设置title集合
        ((HomeRecyclerAdapter.ViewHolderBanner) holder).banner_ItemHomefragment.setBannerTitles
                (list_bannerTiele);
        //设置banner动画效果
        ((HomeRecyclerAdapter.ViewHolderBanner) holder).banner_ItemHomefragment
                .setBannerAnimation(Transformer.DepthPage);
        //设置自动轮播，默认为true
        ((HomeRecyclerAdapter.ViewHolderBanner) holder).banner_ItemHomefragment.isAutoPlay(true);
        //设置轮播时间
        ((HomeRecyclerAdapter.ViewHolderBanner) holder).banner_ItemHomefragment.setDelayTime(3500);
        //设置指示器位置（当banner模式中有指示器时）
        ((HomeRecyclerAdapter.ViewHolderBanner) holder).banner_ItemHomefragment
                .setIndicatorGravity(BannerConfig.CENTER);
        //banner设置方法全部调用完毕时最后调用
        ((HomeRecyclerAdapter.ViewHolderBanner) holder).banner_ItemHomefragment.start();
        //设置banner点击事件的跳转
        final List<BannerContentBean.BannerBean> finalList_banner = list_banner;
        ((ViewHolderBanner) holder).banner_ItemHomefragment.setOnBannerClickListener(new OnBannerClickListener() {
            @Override
            public void OnBannerClick(int position) {

                String activityId = finalList_banner.get(position - 1).getActivityId();
                if (activityId.contains("/")) {
                    String[] split = activityId.split("/");
                    mUrl = mLasUrl + split[0] + "/" + split[0] + "_list?id=" + split[1] +
                            "&share=nativeShare&pageid=" + activityId;
                    Log.i(TAG, "大牌男鞋的网址" + mUrl);
                } else {
                    mUrl = mAndroidUrl + activityId + ".shtml?share=nativeShare&pageid=" +
                            activityId;
                    Log.i(TAG, "其余除了新客专享" + mUrl);
                }
                Intent intent = new Intent(mContext, HomeWebActivity.class);
                intent.putExtra("url", mUrl);
                intent.putExtra("tabIndex", position);
                mContext.startActivity(intent);
            }
        });
    }

    //------------------------------------type1活动时候的json串解析方法---------------------------------------
    private void initType1End(RecyclerView.ViewHolder holder, int position, String s) {
        mJson = mList.get(position).getContent();
        Log.i(TAG, "Type1的content-->>" + mJson);
        List<Type1BeanEnd.AccessAndroidBean> list_accessAndroid = mGson.fromJson(mJson,
                Type1BeanEnd.class).getAccess_android();

        //创建textView数组
        final TextView[] textViewArr = new TextView[list_accessAndroid.size()];
        String title, img, url = "";
        ((HomeRecyclerAdapter.ViewHolderType1) holder).layout_item_type1.removeAllViews();
        for (int i = 0; i < list_accessAndroid.size(); i++) {
//            取每一个的title
            title = list_accessAndroid.get(i).getTitle();
//            取每一个的图片网址
            img = list_accessAndroid.get(i).getImg();
//            取每一个点击跳转的页面
            url = list_accessAndroid.get(i).getUrl();
//            动态创建textView
            textViewArr[i] = new TextView(mContext);
            final int finalI = i;
            Glide.with(mContext).load(img).asBitmap().into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap>
                        glideAnimation) {
//                    将bitmap对象转成drawable对象
                    BitmapDrawable bd = new BitmapDrawable(mContext.getResources(), resource);
                    bd.setBounds(0, 0, bd.getMinimumWidth(), bd.getMinimumHeight());
//                    将当前的textview上边设置图片
                    textViewArr[finalI].setCompoundDrawables(null, bd, null, null);
                }
            });
            //设置textview的属性
            textViewArr[i].setText(title);//设置text的文字
            textViewArr[i].setTextColor(mContext.getResources().getColor(R.color.gray));//设置文字颜色
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup
                    .LayoutParams.MATCH_PARENT);
            lp.weight = 1;
            lp.setMargins(0, 10, 0, 0);
            lp.gravity = Gravity.CENTER;
            textViewArr[i].setLayoutParams(lp);//权重'
            textViewArr[i].setGravity(Gravity.CENTER);
//            在布局中动态添加textView
            ((HomeRecyclerAdapter.ViewHolderType1) holder).layout_item_type1.addView
                    (textViewArr[i]);
//            给textView设置点击事件
            final String finalUrl = url;
            textViewArr[i].setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(mContext, HomeType1Activity.class);
                    //传值
                    intent.putExtra("url", finalUrl);
                    intent.putExtra("tabIndex", finalI);
                    mContext.startActivity(intent);
                }
            });
        }
    }

    //-----------------------活动时候的type=12的json
    // 串解析以及布局显示的方法--------------------------------------------
    private void initType12End(RecyclerView.ViewHolder holder, int position, String mJson) {
//        ((ViewHolderType12) holder).
//        给上边横向布局添加标题
        Type12BeanEnd type12Bean = mGson.fromJson(mJson, Type12BeanEnd.class);
        ((ViewHolderType12) holder).rBtn_itemType12_typename1.setText(type12Bean.getTypename1());
        ((ViewHolderType12) holder).rBtn_itemType12_typename1.setChecked(true);
        ((ViewHolderType12) holder).rBtn_itemType12_typename2.setText(type12Bean.getTypename2());
        ((ViewHolderType12) holder).rBtn_itemType12_typename3.setText(type12Bean.getTypename3());
//        设置type=12 的recyclerView
        GridLayoutManager manager = new GridLayoutManager(mContext, 2);
        ((ViewHolderType12) holder).rv_itemType12.setLayoutManager(manager);
        Type12EndRecyclerAdapter adapter = new Type12EndRecyclerAdapter(mContext, type12Bean
                .getProductType1());
        ((ViewHolderType12) holder).rv_itemType12.setAdapter(adapter);
        ((ViewHolderType12) holder).rv_itemType12.addItemDecoration(new DividerGridItemDecoration
                (mContext));
        ((ViewHolderType12) holder).rv_itemType12.addItemDecoration(new SpacesItemDecoration(5));

    }
    //---------------------------封装倒计时的方法---------------------------------------------------------
    private void countDown(final RecyclerView.ViewHolder holder, final long endTime) {
        final long[] nowTime = new long[1];
        final int[] remaining_time = new int[1];
        final int[] houre_i = new int[1];
        final int[] minute_i = new int[1];
        final int[] second_i = new int[1];
        //得到当前日期的毫秒值
//                    用来检验的
//--------------------------------------------------------------------------------------------------------------
//                    剩余的毫秒值
//                   算法算出时/分/秒的剩余
//                    当时分秒<10的时候 做出09,08的效果
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);

                switch (msg.what) {
                    case 0:
                        //得到当前日期的毫秒值
                        nowTime[0] = System.currentTimeMillis();
//--------------------------------------------------------------------------------------------------------------
//                    剩余的毫秒值
                        remaining_time[0] = (int) ((endTime - nowTime[0]) / 1000);
//                   算法算出时/分/秒的剩余
                        houre_i[0] = remaining_time[0] / 3600;
                        minute_i[0] = (remaining_time[0] % 3600) / 60;
                        second_i[0] = (remaining_time[0] % 3600) % 60;
//                    当时分秒<10的时候 做出09,08的效果
                        if ((houre_i[0] / 10) > 0) {
                            ((ViewHolderType6) holder).tv_house_itemType6.setText(houre_i[0] + "  ");
                        } else {
                            ((ViewHolderType6) holder).tv_house_itemType6.setText("  0" + houre_i[0] + "  ");
                        }
                        if (minute_i[0] / 10 > 0) {

                            ((ViewHolderType6) holder).tv_minute_itemType6.setText("  " + minute_i[0] + "  ");
                        } else {
                            ((ViewHolderType6) holder).tv_minute_itemType6.setText("  0" + minute_i[0]+"  ");

                        }
                        if (second_i[0] / 10 > 0) {
                            ((ViewHolderType6) holder).tv_second_itemType6.setText("  " + second_i[0] + "  ");
                        } else {
                            ((ViewHolderType6) holder).tv_second_itemType6.setText("  0" + second_i[0] + "  ");

                        }
                        handler.sendEmptyMessageDelayed(0,1000);
                }
            }
        };

        handler.sendEmptyMessageAtTime(0, 1000);
    }
}
